using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AnimationPlayer:MonoBehaviour {
	[SerializeField] float timePerFrame;
	[SerializeField] Sprite[] content;
	SpriteRenderer spriteRenderer;
	void Awake() {
		spriteRenderer=GetComponent<SpriteRenderer>();
	}

	int frameIndex;
	float timeThisFrame;

	private void OnEnable() {
		frameIndex=0;
		timeThisFrame=0;
		spriteRenderer.sprite=content[0];
	}

	void Update() {
		timeThisFrame+=Time.deltaTime;
		if(timeThisFrame>=timePerFrame) {
			timeThisFrame-=timePerFrame;
			frameIndex++;
			if(frameIndex<content.Length) spriteRenderer.sprite=content[frameIndex];
			else spriteRenderer.sprite=null;
		}
	}
}
